package com.xxxx.spark.operator

import com.xxxx.spark.WorldCount
import org.apache.spark.{SparkConf, SparkContext}

/**
 * @program: day0305
 * @description: 尽信书，则不如无书
 * @author: CoreDao
 * @create: 2021-03-05 10:28
 * */

object ActionFun {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setMaster("local").setAppName("action_opreator")
    val sc = new SparkContext(conf)

    val file = WorldCount.getClass.getClassLoader.getResource("data/hello.txt").getFile
    val lineRDD = sc.textFile(file)

    /**
     * 行动算子
     * count take(n) first foreach collect
     */
    lineRDD.foreach(println)

    println(lineRDD.count())

    lineRDD.collect().foreach(println)

    lineRDD.take(2).foreach(println)

    println(lineRDD.first())

    sc.stop()
  }
}
